<template>
	<view class="container">
		<view class="empty" v-if="list.length < 1">
			<image class="image" src="@/static/img/empty.png" mode="aspectFit"></image>
			<view class="emptyWord">暂无数据</view>
		</view>
		<block v-else>
			<view class="list">
				<view class="box" hover-class="hoverClass" v-for="item in list" :key="item.id">
					<view class="name">
						{{ item.building_name }}
					</view>
					<view class="btns">
						<view class="btn del" @click="del(item.id)">删除</view>
					</view>
				</view>
			</view>
		</block>
	</view>
</template>

<script>
import api from '@/api/api';
export default {
	data() {
		return {
			list: [],
		};
	},
	onShow() {
		this.getList();
	},
	onPullDownRefresh() {
		this.getList();
	},
	methods: {
		del(id) {
			const _this = this;
			uni.showModal({
				title: '提示',
				content: '确定要删除该楼栋吗？',
				success: function (res) {
					if (res.confirm) {
						api.buildDel({ building_id: id }).then((data) => {
							if (data.data.is_success) {
								uni.showToast({
									title: '删除成功！'
								});
								_this.getList();
							}
						});
					}
				}
			});
		},
		getList() {
			uni.showLoading();
			api.buildList({}).then((data) => {
				this.list = data.data;
				uni.hideLoading();
				uni.stopPullDownRefresh();
			});
		}
	}
};
</script>

<style lang="scss">
.container {
	.list {
		padding: 20rpx;
		.box {
			background: #fff;
			border-radius: 16rpx;
			margin-bottom: 20rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 20rpx;
			.name {
				font-size: 28rpx;
				font-weight: bold;
			}
			.btns {
				display: flex;
				.btn {
					font-size: 26rpx;
					margin-left: 20rpx;
					width: 60rpx;
					height: 60rpx;
					text-align: center;
					line-height: 60rpx;
					&.edit {
						color: $uni-primary;
					}
					&.del {
						color: $uni-error;
					}
				}
			}
		}
	}
}
</style>
